package com.hd.crdao.wrapper;

import com.hd.crdao.utils.ALog;
import com.tencent.bugly.crashreport.CrashReport;

import java.util.HashMap;
import java.util.Map;

//bugly回调
public class AppCrashHandleCallback extends CrashReport.CrashHandleCallback {
    @Override
    public synchronized Map<String, String> onCrashHandleStart(int crashType, String errorType, String errorMessage, String errorStack) {
        String crashTypeName;
        switch (crashType) {
            case CrashReport.CrashHandleCallback.CRASHTYPE_JAVA_CATCH:
                crashTypeName = "JAVA_CATCH";
                break;
            case CrashReport.CrashHandleCallback.CRASHTYPE_JAVA_CRASH:
                crashTypeName = "JAVA_CRASH";
                break;
            case CrashReport.CrashHandleCallback.CRASHTYPE_NATIVE:
                crashTypeName = "JAVA_NATIVE";
                break;
            case CrashReport.CrashHandleCallback.CRASHTYPE_U3D:
                crashTypeName = "JAVA_U3D";
                break;
            default: {
                crashTypeName = "unknown";
            }
        }

        ALog.e("Crash Happen Type:" + crashType + " TypeName:" + crashTypeName);
        ALog.e("errorType:" + errorType);
        ALog.e("errorMessage:" + errorMessage);
        ALog.e("errorStack:" + errorStack);

        Map<String, String> userDatas = super.onCrashHandleStart(crashType, errorType, errorMessage, errorStack);
        if (userDatas == null) {
            userDatas = new HashMap<>();
        }

        userDatas.put("DEBUG", "TRUE");
        return userDatas;
    }

}